<script setup>
function fn(name,age=17){
    console.log(name+","+age);
}
function fn2(...values){
    console.log(values.length);
}

var af1 = v => v;

var af2 = (a,b) => a+b;

var af3 = (a,b) => {
    return a+b;
};

var af4 = (id,name) => ({id: id, name: name});

var af5 = () => {
    // 箭头函数里面没有 this 对象
    console.log(this);
}

function fn3(){
  setTimeout(()=>{
    // 定义时，this 绑定的是 fn 中的 this 对象
    console.log(this);
  },0)
}



var btnclick=function(){
    fn("Amy",18);  // Amy,18
    fn("Amy","");  // Amy,
    fn("Amy");     // Amy,17

    fn("David");
    fn("David",undefined);
    fn("David",null);

    fn2(1,2);      //2
    fn2(1,2,3,4);  //4

    console.log(af1(1));
    console.log(af2(1,2));
    console.log(af3(1,2));
    console.log(af4(1,"Amy"));
    af5();
    console.log(this);

    // fn3 的 this 对象为 {a: 18}
    fn3.call({a: 18});  // 18
    fn3.call(); 

};
</script>
<template>
    <button @click="btnclick">按钮</button>
</template>